package com.cunshe.service;

import com.cunshe.dao.CaseDao;
import com.cunshe.domain.TestCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CaseService {

    @Autowired
    private CaseDao caseDao;

    @Transactional(rollbackFor = Exception.class)
    public int insert(TestCase record) {
        return caseDao.insert(record);
    }

    @Transactional(rollbackFor = Exception.class)
    public int delete(Long id) {
        return caseDao.delete(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public int update(TestCase record) {
        return caseDao.update(record);
    }

    public TestCase get(Long id) {
        return list(TestCase.builder().id(id).build())
                .stream()
                .findFirst()
                .orElse(null);
    }

    public List<TestCase> getByMenuId(Long menuId) {
        return list(TestCase.builder().menuId(menuId).build());
    }

    public List<TestCase> list(TestCase record) {
        return caseDao.list(record);
    }

}